// By Zooloo75 / TPWCAS

//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "aisuppress\fn_evasiveMove.sqf"
#include <core_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_unit","_anim","_randomPos","_chance"];

DEFAULT_PARAM(_unit,0,objNull);
if(currentWeapon _unit == "") exitWith {};

_bullet_cnt = _unit getVariable [QGVAR(BULLET_COUNT),0];
if (_bullet_cnt >= GVAR(MIN_BULLET_FOR_PRONE)) then {
	_unit setUnitPos "middle";
	_unit setUnitPosWeak "down";
} else {
	_unit setUnitPos "auto";
	_unit setUnitPosWeak "middle";
};
(group _unit) setSpeedMode "FULL";
(group _unit) setBehaviour "COMBAT";

_chance = random 100;
if(_chance > 40) then {	
	_anim = round(random 10);
	_randomPos = [(getPosATL _unit select 0) + random 15 - random 15,(getPosATL _unit select 1) + random 15 - random 15,0];

	_unit doMove _randomPos;

	switch _anim do
	{
		case 0:
		{
			_unit playMoveNow "AmovPercMevaSrasWrflDfr_AmovPknlMstpSrasWrflDnon";	
		};
		
		case 1:
		{
			_unit playMoveNow "AmovPercMevaSrasWrflDf_AmovPknlMstpSrasWrflDnon";	
		};
		
		case 2:
		{
			_unit playMoveNow "AmovPercMevaSrasWrflDfl_AmovPknlMstpSrasWrflDnon";	
		};
		
		case 3:
		{
			_unit playMoveNow "AmovPercMevaSrasWrflDl";	
		};
		
		case 4:
		{
			_unit playMoveNow "AmovPercMevaSrasWrflDr";	
		};
		
		case 5:
		{
			_unit playMoveNow "AmovPknlMevaSrasWrflDf";	
		};
		
		case 6:
		{
			_unit playMoveNow "AovrPercMrunSrasWrflDf";
		};
		
		case 7:
		{
			_unit playMoveNow "AmovPknlMevaSrasWrflDl";
		};
		
		case 8:
		{
			_unit playMoveNow "AmovPknlMevaSrasWrflDr";
		};
		
		case 9:
		{
			_unit playMoveNow "AmovPercMstpSrasWrflDnon_AadjPpneMstpSrasWrflDright";
			[_unit] spawn
			{
				_unit = _this select 0;
				sleep (3 + random 3);
				_unit playMoveNow "AmovPpneMevaSlowWrflDf";
			};
		};
		
		case 10:
		{
			_unit playMoveNow "AmovPercMstpSrasWrflDnon_AadjPpneMstpSrasWrflDleft";
			[_unit] spawn
			{
				_unit = _this select 0;
				sleep (3 + random 3);
				_unit playMoveNow "AmovPpneMevaSlowWrflDf";
			};
		};
	};			

	if(_chance > 95) then
	{
		_unit forceWeaponFire [currentWeapon _unit, "Single"];
	};
};

TRACE("End");
TMFPROFILERSTOP;
